package com.lphl.pet.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.Handler;

public class EditImage {
    public boolean mWaitingToPick; // Whether we are wait the user to pick a face.
    public boolean mSaving; // Whether the "save" button is already clicked.
    private Context mContext;
    private Handler mHandler = new Handler();
    private Bitmap mBitmap;

    public EditImage(Context context) {
        mContext = context;
    }

    /**
     * 图片旋转
     *
     * @param degree
     */
    public Bitmap rotate(Bitmap bmp, float degree) {
        Matrix matrix = new Matrix();
        matrix.postRotate(degree);
        int width = bmp.getWidth();
        int height = bmp.getHeight();
        Bitmap bm = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
        return bm;
    }

    /**
     * 图片反转
     *
     * @param bm
     * @param flag
     * @return
     */
    public Bitmap reverse(Bitmap bmp, int flag) {
        float[] floats = null;
        switch (flag) {
            case 0: // 水平反转
                floats = new float[]{-1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f};
                break;
            case 1: // 垂直反转
                floats = new float[]{1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 1f};
                break;
        }
        if (floats != null) {
            Matrix matrix = new Matrix();
            matrix.setValues(floats);
            Bitmap bm = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
            return bm;
        }
        return null;
    }
}
